#include <iostream>

int countTotalOnes(int n) {
	int factor = 1;
	int count = 0;
	int left, current, right;
	while (n / factor) {
		left = n / (factor * 10);
		current = (n / factor) % 10;
		right = n % factor;
		switch (current) {
		case 0:
			count += left * factor;
			break;
		case 1:
			count += left * factor + right + 1;
			break;
		default:
			count += (left + 1) * factor;
		}

		factor *= 10;
	}
	return count;
}
int mainCount1s() {
	std::cout << countTotalOnes(213) << std::endl;

	return 0;
}